<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>015组件参数校验与非props特性</title>
  <script src="./vue.js"></script>
</head>

<body>
  <div id="root">
    <child :content="content"></child>
  </div>
  <script>
    var vm = new Vue({
      el: "#root",
      data: {
        content: "hello world"
        // content: 123446
      },
      components: {
        "child": {
          // 无校验写法
          // props: ["content"],
          // 有校验写法
          props: {
            // content: String
            // content: Number
            // content: [ String, Number ]
            content: {
              type: [String, Number ],
              // content是否为必传
              require: false,   
              default: "default value",
              // 校验器
              validator: function(value) {
                return (value.length > 5)
              }
            }
          },
          template: "<div>Child--{{content}}</div>"
        }
      },
      methods: {

      }
    })
  </script>
</body>

</html>